<?php
namespace ITSociaal\Themes\HuisVanHerstel\Hooks;

/**
 * Formatting and tidying hooks
 */
class Formatting implements HooksInterface
{
	/**
	 * Removes " /" from " />"
	 *
	 * @param string $element Markup of single element
	 *
	 * @return string
	 */
	protected function removeXmlSlash($element)
	{
		return str_replace(" />", ">", $element);
	}

	/**
	 * script_loader_tag filter handler
	 */
	public function filterScriptLoaderTag($tag)
	{
		return strtr($tag, "'", "\"");
	}

	/**
	 * site_icon_meta_tags filter handler
	 *
	 * @param array $meta_tags
	 *
	 * @return array
	 */
	public function filterSiteIconMetaTags($meta_tags)
	{
		return array_map([$this, "removeXmlSlash"], $meta_tags);
	}

	/**
	 * style_loader_tag filter handler
	 *
	 * @param string $html
	 *
	 * @return string
	 */
	public function filterStyleLoaderTag($html)
	{
		return $this->removeXmlSlash(
			strtr(
				$html,
				[
					"='"  => "=\"",
					"' "  => "\" ",
					" h"  => "h",
				]
			)
		);
	}
}

/* vi:set ts=4 sw=4 noet: */
